<template>
  <div class="companyDetail">
    <!-- 我是 companyDetail -->
    <div class="detail-top">
      <van-nav-bar @click-left="$router.back()">
        <template #left>
          <i class="iconfont arrow iconbtn_nav_back"></i>
        </template>
      </van-nav-bar>
      <div class="top-middle">
        <div class="middle-left">
          <div class="titel">{{ companyInfo.name }}</div>
          <div class="info">
            <span>{{ companyInfo.type }}</span>
            <span>{{ companyInfo.step }}</span>
            <span>{{ companyInfo.scale }}</span>
          </div>
        </div>
        <div class="middle-right">
          <img class="avatar" :src="baseUrl + companyInfo.logo" />
        </div>
      </div>
      <div class="temporal">
        <span>
          <i class="iconfont iconicon_gongsi_time"></i>
          {{ companyInfo.workTime }}
        </span>
        <span>
          <i class="iconfont iconicon_gongsi_sx"></i>
          {{ companyInfo.restDay }}
        </span>
        <span>
          <i class="iconfont iconicon_gongsi_jiaban"></i>
          {{ companyInfo.overtime }}
        </span>
      </div>
      <div class="channel">
        <van-tabs line-height="0">
          <van-tab v-for="(item, index) in companyInfo.weals" :key="index">
            <template #title>
              <span class="channel-sytle">
                <van-button plain type="primary">
                  <i class="iconfont" :class="item.icon"></i>
                  {{ item.text }}</van-button
                >
              </span>
            </template>
          </van-tab>
        </van-tabs>
      </div>
    </div>
    <!-- 公司地址 -->
    <div class="companyLocal">
      <van-cell>
        <template #title>
          <div class="title">公司地址</div>
          <div class="local">
            <span>{{ companyInfo.address }}</span>
            <span></span>
          </div>
          <div class="juli">
            距离当前50m, 步行需要57秒
          </div>
        </template>
        <template #default>
          <div class="value">全部地址<van-icon name="arrow" /></div>
          <div class="daohan">
            <van-button class="daohao-btn" plain type="info"  @click="$router.push('/map')"
              ><i class="iconfont icon-icon-test"></i>导航</van-button
            >
          </div>
        </template>
      </van-cell>
    </div>
    <!-- 公司简介 -->
    <div class="company-profile">
      <van-cell>
        <template #title>
          <div class="title">公司简介</div>
        </template>
      </van-cell>
      <div
        v-html="companyInfo.desc"
        class="jianjie1"
        :class="moreShow ? 'jianjie' : ''"
      ></div>
      <div class="look-more" v-show="moreShow" @click="lookMore">
        查看更多<van-icon class="icon" name="arrow-down" />
      </div>
    </div>
    <!-- 公司照片 -->
    <div class="companyPic">
      <van-cell>
        <template #title>
          <div class="title">公司照片</div>
        </template>
      </van-cell>
      <van-tabs line-height="0">
        <van-tab
          v-for="(itempci, indexpic) in companyInfo.sliders"
          :key="indexpic"
        >
          <template #title>
            <span class="company-pic">
              <img class="pic" :src="baseUrl + itempci" />
            </span>
          </template>
        </van-tab>
      </van-tabs>
    </div>
    <!-- 工商信息 -->
    <div class="business-information">
      <van-cell>
        <template #title>
          <div class="title">工商信息</div>
        </template>
      </van-cell>
      <div class="busi-info">
        <div class="item">
          <span class="left">公司全称</span>
          <span class="right">{{ companyInfo.fullname }}</span>
        </div>
        <div class="item">
          <span class="left">成立时间</span>
          <span class="right">{{ companyInfo.establishedTime }}</span>
        </div>
        <div class="item">
          <span class="left">注册资本</span>
          <span class="right">{{ companyInfo.capital }}</span>
        </div>
        <div class="item">
          <span class="left">法人代表</span>
          <span class="right">{{ companyInfo.legalPerson }}</span>
        </div>
        <div class="item">
          <span class="left">信息来源</span>
          <span class="right">{{ companyInfo.messageSource }}</span>
        </div>
      </div>
    </div>
    <!-- 面试评价 -->
    <div class="mianshi-evaluate">
      <van-cell>
        <template #title>
          <div class="title">面试评价</div>
        </template>
        <template #default>
          <div class="value" @click="opencompop">写评价</div>
        </template>
      </van-cell>
      <div class="comres-model">
        <div class="left-score">
          <div class="top">
            <span>{{ value }}</span
            >分
          </div>
          <div class="scpre-start">
            <!-- <van-rate
              v-model="value"
              :size="20"
              color="#ffd21e"
              void-icon="star"
              void-color="#eee"
            /> -->
            <van-rate readonly v-model="value" color="#ffd21e" />
          </div>
        </div>
        <div class="xiangqing">
          <div class="item">
            <span class="left">岗位描述</span>
            <span
              ><van-rate
                readonly
                :size="16"
                v-model="poaitionValue"
                color="#ffd21e"
            /></span>
          </div>
          <div class="item">
            <span class="left">面试情况</span>
            <span
              ><van-rate readonly :size="16" v-model="viewValue" color="#ffd21e"
            /></span>
          </div>
          <div class="item mianshig">
            <span class="left">面试官</span>
            <span
              ><van-rate
                readonly
                :size="16"
                v-model="interviewValue"
                color="#ffd21e"
            /></span>
          </div>
        </div>
      </div>
    </div>
    <!-- 评论列表模块 -->
    <div class="comment">
      <van-list
        v-model="loading"
        :finished="finished"
        finished-text="没有更多了"
        @load="onLoad"
      >
        <van-cell v-for="(comitem, comindex) in commentList" :key="comindex">
          <template #title>
            <div class="user">
              <img class="userpic" :src="baseUrl + comitem.user.avatar" />
              <div class="userinfo">
                <div class="names">{{ comitem.user.nickname }}</div>
                <div class="gangwei">
                  <span>面试岗位: {{ comitem.position }}</span>
                </div>
                <div class="com-dain">
                  <span
                    v-for="(miaoshuitem, miaoshuindex) in tagsList"
                    :key="miaoshuindex"
                    >{{ miaoshuitem }}</span
                  >
                  <!-- <span>面试效率高</span> -->
                </div>
                <div class="com-content">
                  {{ comitem.content }}
                </div>
                <div class="current-time">
                  {{ comitem.created_at | formatTime }}
                </div>
              </div>
            </div>
          </template>
          <template #default>
            <span
              ><van-rate readonly :size="16" v-model="onceSocre" color="#ffd21e"
            /></span>
          </template>
        </van-cell>
      </van-list>
    </div>
    <!-- 下半部分的定位模块 -->
    <div class="business-btm">
      <div class="left">
        <van-button
          plain
          type="info"
          @click="$router.push(`/companyPosition/${$route.params.id}`)"
          >在招职位<span class="nums">{{
            companyInfo.positions
          }}</span></van-button
        >
      </div>
      <div class="right">
        <van-button
          plain
          type="info"
          @click="$router.push(`/technicList/${$route.params.id}`)"
          >企业面试题<span class="nums">{{
            companyInfo.questions
          }}</span></van-button
        >
      </div>
    </div>
    <!-- 评论的弹框 -->
    <div class="compop">
      <writecom ref="writecom" @addComments="addComments"></writecom>
    </div>
  </div>
</template>

<script>
// 导入写评论组件
import writecom from './writecom.vue'
// 接口
import { companyDetail, companyComments } from '@/api/api.js'
export default {
  components: {
    writecom
  },
  data () {
    return {
      moreShow: true,
      value: 2.5, // 总评分
      comShow: false,
      companyInfo: {}, // 公司详情信息
      baseUrl: process.env.VUE_APP_URL,
      poaitionValue: 0, // 面试描述
      viewValue: 0, // 岗位描述
      interviewValue: 0, // 面试官
      onceSocre: 2.5, // 每个人评论的分数
      limit: 5,
      start: 0,
      loading: false,
      finished: false,
      commentList: [], // 企业评论数据
      tagsList: [] // 描述
    }
  },
  // 页面进来就加载
  async created () {
    this.getCompanyInfo()
    this.$toast.loading({
      message: '加载中...',
      forbidClick: true
    })
  },
  methods: {
    addComments (value) {
      this.commentList.unshift(value)
    },
    // 点击查看更多
    lookMore () {
      this.moreShow = false
    },
    // 点击打开写评论面板
    opencompop () {
      this.$refs.writecom.comShow = true
    },
    // 得到公司详情
    async getCompanyInfo () {
      const res = await companyDetail(this.$route.params.id)

      this.companyInfo = res.data.data
      this.poaitionValue = res.data.data.score.interviewScore
      this.viewValue = res.data.data.score.interviewerScore
      this.interviewValue = res.data.data.score.positionScore

      const pingjun =
        (Number(this.poaitionValue) +
          Number(this.viewValue) +
          Number(this.interviewValue)) /
        3
      this.value = Number(pingjun.toFixed(1))
    },

    // 评论数据
    async onLoad () {
      const res = await companyComments({
        id: this.$route.params.id,
        limit: this.limit,
        start: this.start
      })

      this.commentList = [...this.commentList, ...res.data.data.list]
      res.data.data.list.forEach(item => {
        const everSorce =
          (Number(item.positionScore) +
            Number(item.interviewScore) +
            Number(item.interviewerScore)) /
          3
        this.onceSocre = Number(everSorce.toFixed(1))
        this.tagsList = item.tags
      })

      this.start += this.limit
      this.loading = false
      // res.data.data.total / this.limit
      // 判断是否加载完毕
      const nums = Math.ceil(res.data.data.total / this.limit) * this.limit
      // console.log(nums)
      // 判断
      if (this.start === nums) {
        this.finished = true
      }
    }
  }
}
</script>

<style lang="less" scoped>
.companyDetail {
  margin-bottom: 100px;
  margin-top: 248px;
  .detail-top {
    width: 100%;
    height: 238px;
    background-color: #181a39;
    position: fixed;
    top: 0px;
    left: 0px;
    z-index: 100;
    /deep/ .van-nav-bar {
      background-color: transparent;
    }
    /deep/ [class*='van-hairline']::after {
      border: 0;
    }
    .arrow {
      color: #ffffff;
      font-size: 38px;
      font-weight: 700;
    }
    .top-middle {
      display: flex;
      color: #ffffff;
      padding: 0 15px;
      margin-top: 20px;
      .middle-left {
        flex: 8;
        .titel {
          font-size: 20px;
          font-weight: 700;
          margin-bottom: 10px;
        }
        .info {
          span {
            font-size: 12px;
            margin-right: 10px;
            border: 1px solid #a3a3b0;
            padding: 3px 5px;
            color: #a3a3b0;
            border-radius: 3px;
          }
        }
      }
      .middle-right {
        flex: 4;
        text-align: right;
        .avatar {
          width: 50px;
          height: 50px;
        }
      }
    }
    .temporal {
      display: flex;
      align-items: center;
      font-size: 12px;
      color: #ffffff;
      padding: 0 15px;
      margin-top: 20px;
      span {
        margin-right: 15px;
      }
    }
    .channel {
      margin-top: 15px;
      // padding: 0 15px;
      /deep/ .van-tabs__nav {
        background-color: transparent;
      }
      /deep/ .van-tab {
        color: #ffffff !important;
      }
      .biaoqian {
        color: #ffffff;
      }
      .channel-sytle {
        display: inline-block;
        padding-right: 5px;
        /deep/ .van-button--plain {
          background-color: transparent;
        }
        /deep/ .van-button {
          width: 100px;
          height: 40px;
          line-height: 40px;
          border-radius: 5px;
          font-size: 10px;
          position: relative;
          i {
            display: inline-block;
            position: absolute;
            top: -3px;
            left: 7px;
            font-size: 24px;
            // padding-right: 4px;
            margin-right: 10px;
          }
        }
        /deep/ .van-button--plain.van-button--primary {
          color: #a3a3b0;
        }
        /deep/ .van-button--primary {
          border: 1px solid #a3a3b0;
        }
        /deep/ .van-button--normal {
          padding: 0;
        }
        /deep/ .van-button__text {
          margin-left: 25px;
        }
        /deep/ .van-tabs__wrap--scrollable .van-tab {
          padding: 0px;
        }
      }
    }
  }
  .companyLocal {
    margin-top: 20px;

    .title {
      font-size: 20px;
    }
    .local {
      margin: 15px 0 5px 0;
    }
    .juli {
      font-size: 12px;
      color: #b4b4bd;
    }
    .value {
      color: #5b5d75;
    }
    /deep/ .van-cell__title {
      flex: 9;
    }
    /deep/ .van-cell__value {
      flex: 3;
      .daohan {
        position: relative;
        .daohao-btn {
          position: absolute;
          bottom: -50px;
          right: 0px;
          border: 1px solid #b4b4bd;
          border-radius: 20px;
          width: 80px;
          height: 35px;
        }
      }
    }
    /deep/ .van-button--plain.van-button--info {
      color: #6d6f84;
    }
  }
  .company-profile {
    margin-top: 20px;
    padding: 0 15px;
    .title {
      font-size: 20px;
      padding-left: 0px;
      margin-bottom: 15px;
    }
    .van-cell {
      padding: 0px;
    }
    .jianjie {
      font-size: 16px;
      display: -webkit-box;
      -webkit-box-orient: vertical;
      -webkit-line-clamp: 6;
      overflow: hidden;
    }
    .jianjie1 {
      font-size: 16px;
    }
    .look-more {
      width: 100%;
      text-align: center;
      height: 40px;
      line-height: 40px;
      color: #545671;
      font-size: 14px;
      position: relative;
      .icon {
        display: inline-block;
        margin-left: 5px;
        font-size: 18px;
        position: absolute;
        top: 10px;
        left: 57%;
      }
    }
  }
  .companyPic {
    margin-top: 20px;
    padding: 0 15px;
    .title {
      font-size: 20px;
      padding-left: 0px;
      margin-bottom: 15px;
    }
    .van-cell {
      padding: 0px;
    }
    // /deep/ .van-tab {
    //   height: 200px;
    // }
    // /deep/ .van-tab--active {
    //   display: block;
    //   height: 100%;
    // }

    .company-pic {
      // height: 100%;
      .pic {
        width: 150px;
        height: 100px;
        border-radius: 7px;
      }
    }
    /deep/ .van-tabs--line .van-tabs__wrap {
      height: 150px;
    }
    /deep/ .van-tabs__wrap--scrollable .van-tabs__nav--complete {
      padding: 0px;
    }
    /deep/ .van-tabs__wrap--scrollable .van-tab {
      padding: 0;
    }
    /deep/ .van-tab {
      margin-right: 10px;
    }
  }
  .business-information {
    // height: 1000px;
    margin-top: 20px;
    padding: 0 15px;
    .title {
      font-size: 20px;
      padding-left: 0px;
      margin-bottom: 20px;
    }
    .van-cell {
      padding: 0px;
    }
    .busi-info {
      .item {
        font-size: 16px;
        .left {
          color: #b4b4bd;
          margin-right: 30px;
        }
        .right {
          font-size: 14px;
          color: #545671;
        }
        margin-bottom: 15px;
      }
    }
  }
  .mianshi-evaluate {
    // height: 500px;
    margin-top: 50px;
    padding: 0 15px;
    .title {
      font-size: 20px;
      padding-left: 0px;
      margin-bottom: 20px;
    }
    .value {
      font-size: 18px;
      color: #181a39;
    }
    .van-cell {
      padding: 0px;
    }
    .comres-model {
      width: 100%;
      height: 150px;
      background-color: #f7f7f7;
      display: flex;
      padding: 20px 0;
      .left-score {
        flex: 5;
        border-right: 1px solid #cccccc;
        padding-top: 15px;
        text-align: center;
        .top {
          margin-bottom: 10px;
          font-size: 18px;
          span {
            font-size: 30px;
            color: #00b8d4;
          }
        }
      }
      .xiangqing {
        flex: 7;
        font-size: 14px;
        padding-top: 15px;
        padding-left: 15px;
        text-align: center;
        .item {
          margin-bottom: 15px;
          span {
            margin-right: 20px;
            // margin: 0 20px;
          }
        }
        .item:last-child {
          text-align: left;
          padding-left: 3px;
          .left {
            padding-right: 10px;
          }
        }
      }
    }
  }
  .comment {
    // height: 500px;
    margin-top: 30px;
    font-size: 12px;
    // display: flex;
    .user {
      display: flex;
      .userpic {
        margin-right: 15px;
        width: 45px;
        height: 45px;
        border-radius: 50%;
      }
      .userinfo {
        .names {
          font-size: 12px;
          font-weight: 700;
        }
        .gangwei {
          color: #b4b4bd;
          font-size: 10px;
          margin-top: -8px;
        }
        .com-dain {
          font-size: 12px;
          span {
            color: #b4b4bd;
            background-color: #f7f4f5;
            padding-top: 2px;
            padding-right: 4px;
            padding-bottom: 2px;
            margin-right: 5px;
          }
        }
        .com-content {
          margin: 10px 0;
          font-size: 14px;
        }
        .current-time {
          font-size: 14px;
          color: #b4b4bd;
        }
      }
    }
    /deep/ .van-cell__title {
      flex: 8;
    }
    /deep/ .van-cell__value {
      flex: 4;
    }
  }
  .business-btm {
    position: fixed;
    bottom: 0;
    left: 0;
    width: 100%;
    height: 90px;
    background-color: #ffffff;
    display: flex;
    padding-top: 10px;
    .left {
      flex: 1;
      text-align: center;
      padding: 0 15px;
      .nums {
        font-size: 10px;
        position: absolute;
        top: 5px;
        right: 30px;
      }
    }
    .right {
      flex: 1;
      padding: 0 15px;
      text-align: center;
      .nums {
        font-size: 10px;
        position: absolute;
        top: 5px;
        right: 25px;
      }
    }
    .left,
    .right {
      position: relative;
      font-size: 16px;
    }
    /deep/ .van-button--info {
      border: 1px solid #29292a;
    }
    /deep/ .van-button--plain.van-button--info {
      color: #181a39;
    }
    /deep/ .van-button {
      width: 100%;
      border-radius: 7px;
      font-size: 16px;
    }
  }
}
</style>
